package com.lantosec.hmrp.core.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lantosec.hmrp.modules.system.entity.SysParameter;
import com.lantosec.hmrp.modules.system.service.ISysParameterService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

@Configuration
public class InitDataListener implements InitializingBean, ServletContextAware {

    @Autowired
    private ISysParameterService service;

    public static String rootPath;
    public static String imgPath;
    public static String thumbnailPath;
    public static String filePath;
    public static String uploadsUrl;

    @Override
    public void afterPropertiesSet() throws Exception {

    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        rootPath = service.getOne(new QueryWrapper<SysParameter>().eq(String.valueOf(SysParameter.ColName.para_name), "rootPath")).getParaValue();
        imgPath = service.getOne(new QueryWrapper<SysParameter>().eq(String.valueOf(SysParameter.ColName.para_name), "imgPath")).getParaValue();
        thumbnailPath = service.getOne(new QueryWrapper<SysParameter>().eq(String.valueOf(SysParameter.ColName.para_name), "thumbnailPath")).getParaValue();
        filePath = service.getOne(new QueryWrapper<SysParameter>().eq(String.valueOf(SysParameter.ColName.para_name), "filePath")).getParaValue();
        uploadsUrl = service.getOne(new QueryWrapper<SysParameter>().eq(String.valueOf(SysParameter.ColName.para_name), "uploadsUrl")).getParaValue();
    }
}
